<!-- 移动签批->公文校对单 -->
<template>
  <view>
    <van-tabs color="#1989fa" title-active-color="#1989fa" animated swipeable @change="onChange">
      <van-tab title="公文详情" name="gwxq">
        <van-collapse v-model="tableShow" accordion :border="border">
          <van-collapse-item title="基本信息" title-class="text-bold" name="jbxx">
            <template #title>
              <view :class="tableShow == 'jbxx' ? 'content-blue':''">
                <i class="van-icon van-icon-label-o van-cell__left-icon"></i>
                <span class="van-cell__title text-bold">
                  基本信息
                </span>
              </view>
            </template>
            <van-cell-group :border="border">
              <van-row class="content-border">
                <van-col span="8" class="content-title">标题(排版单)</van-col>
                <van-col span="16" class="content-value text-blue" @click="openDetail">{{ detailBody.title }}</van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">签批件</van-col>
                <van-col span="16" class="content-value text-blue" @click="openFw">签批件</van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">拟稿人</van-col>
                <van-col span="16" class="content-value">{{ detailBody.drafterName }}</van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">拟稿时间</van-col>
                <van-col span="16" class="content-value">{{ detailBody.drafterTime }}</van-col>
              </van-row>
            </van-cell-group>
          </van-collapse-item>

          <van-collapse-item title="正文及附件" title-class="text-bold" name="zwjfj">
            <template #title>
              <view :class="tableShow == 'zwjfj' ? 'content-blue':''">
                <i class="van-icon van-icon-font-o van-cell__left-icon"></i>
                <span class="van-cell__title text-bold">
                  正文及附件
                </span>
              </view>
            </template>
            <view class="opinion" v-if="detailDoc != null && detailDoc.length > 0 ">
              <text class="opinion-left">正文</text>
              <view class="opinion-right">
                <view v-for="item in detailDoc" @click="lx.openFile(item, proInstId)">
                  <text class="text-blue">{{ item.attachName }}</text>
                </view>
              </view>
            </view>
            <view class="opinion" v-if="detailAttachment != undefined && detailAttachment.length > 0 ">
              <text class="opinion-left">附件</text>
              <view class="opinion-right">
                <view v-for="item in detailAttachment"  @click="lx.openFile(item, proInstId)">
                  <text class="text-blue">{{ item.attachName }}</text>
                </view>
              </view>
            </view>
            <view class="opinion" v-if="detailOfd != undefined && detailOfd.length>0 ">
              <text class="opinion-left">排版文件</text>
              <view class="opinion-right">
                <view v-for="item in detailOfd"  @click="lx.openFile(item, proInstId)">
                  <text class="text-blue">{{ item.attachName }}</text>
                </view>
              </view>
            </view>
          </van-collapse-item>

          <van-collapse-item title="意见" title-class="text-bold" name="yj">
            <template #title>
              <view :class="tableShow == 'yj' ? 'content-blue':''">
                <i class="van-icon van-icon-comment-o van-cell__left-icon"></i>
                <span class="van-cell__title text-bold">
                  意见
                </span>
              </view>
            </template>
            <view v-if="opinion != null">
              <template v-for="(itemOpinion,index) in reviewType">
                <view class="opinion" v-if="opinion[itemOpinion.dictItemCode] != undefined">
                  <view class="opinion-title">{{ itemOpinion.dictItemName }}</view>
                  <view class="opinion-box padding-left-sm"
                        v-for="(item,index) in opinion[itemOpinion.dictItemCode]" :key="index">
                    <!--如果和上一项意见的部门相同，则隐藏部门-->
                    <view class="opinion-left text-bold"
                          v-if="!(index>0 && opinion[itemOpinion.dictItemCode][index-1].parentDeptCode == item.parentDeptCode)">
                      {{ item.parentDeptName }}
                    </view>
                    <view class="opinion-left">{{ item.opinion }}</view>
                    <view class="opinion-left">{{ item.attachName }}</view>
                    <view class="opinion-right">
                      <!-- base64签名图片 -->
                      <img v-if="item.signature!='' && item.signature != undefined"
                           :src="`data:image/png;base64,`+item.signature" alt="图片未上传"/>
                      <text v-else class="opinion-user">{{ item.userName }}</text>
                      <text class="opinion-date">{{ item.approvalTime }}</text>
                    </view>
                  </view>
                </view>
              </template>
            </view>
          </van-collapse-item>
        </van-collapse>
      </van-tab>
      <van-tab title="版式稿纸" name="bsgz">
        <read :opinionInfo="opinion" :detailBodyInfo="detailBody" :proofBodyInfo="proofBody"
              :detailDocInfo="detailDoc" :detailOfdInfo="detailOfd" :detailAttachmentInfo="detailAttachment" ></read>
      </van-tab>
      <van-tab title="流转过程" name="lzgc" :key='2'>
        <docProcess :dataList="dataList"></docProcess>
      </van-tab>
    </van-tabs>
    <trans ref="trans" :proInstId="proInstId" @refreshBtnGroup="refreshBtnGroup" :showTrans="showTrans"
           @closeTrans="closeTrans" :paramObject="paramObject" :detailObject="detailBody"></trans>
    <detail ref="detail" :showDetail="showDetail" @closeDetail="closeDetail" ></detail>

    <div style="height: 5rem;">
      <van-tabbar v-model="active">
        <van-tabbar-item v-for="(item,index) in barList" :key="index" v-if="index < 4" :name="item.name"
                         @click="onClick(item.operation)">
          <span>{{ item.value }}</span>
          <template #icon="props">
            <img :src="props.active ? item.iconTab.active : item.iconTab.inactive"/>
          </template>
        </van-tabbar-item>
      </van-tabbar>
    </div>

    <van-popup v-model="showCompo" closeable round position="bottom" :style="{ height: '100%' }"
               @click-close-icon="toClose" @click-overlay="toClose">
      <fw class="margin-top-xl" ref="fwRef" :instId="fwInfo.proInstId"></fw>
    </van-popup>
  </view>
</template>

<script>
import trans from 'pages/caac/components/gwjddDoc/compo-trans';
import detail from 'pages/caac/components/gwjddDoc/compo-detail';
import read from 'pages/caac/components/gwjddDoc/compo-read';
import docProcess from 'pages/caac/components/gwjddDoc/compo-process';
import fw from 'pages/caac/send/index';

export default {
  components: {
    trans,
    detail,
    read,
    docProcess,
    fw,
  },
  onLoad: async function (option) {
    await this.$onLaunched //解決bug：执行完onLaunch后再执行页面onLoad
    // 从缓存获取用户信息
    this.userInfo = this.cache.get('userInfo')
    // 从地址栏获取proInstId
    this.proInstId = option.proInstId
    if (this.proInstId != undefined && this.proInstId != '') {
      // 获取要显示的按钮
      await this.getButtonsData(this.proInstId)
      // 意见
      await this.getCaacOpinion(this.proInstId)
      // 详情
      await this.getCaacDetail(this.proInstId)
    }
  },

  data() {
    return {
      title: '',   // 标题
      border: false,
      tableShow: "jbxx",
      proInstId: '',
      configCode: '',
      userInfo: {},		 // 当前登录用户信息，目前先从缓存中获取
      paramObject: {}, // openwfneededdata数据
      optionBtn: null, //
      buttonArr: [],    // 要显示的功能按钮
      barList: [],
      showShare: false,     // 更多
      active: '',
      detailBody: {},
      proofBody: {},
      detailDoc: [],
      detailAttachment: [],
      detailOfd: [],
      opinion: {},
      showTrans: false, // 显示流转
      showDetail: false, // 显示详情
      fwInfo: {}, // 发文详情
      reviewType: [],  // 意见类型
      dataList: {
        docProcess: {}, //流转过程
        signProcess: [],//会签件
      },
      showCompo: false,
    }
  },

  mounted() {
    // 处理页面弹出层初始化
    this.active = 'gwxq'
    // 意见类型
    this.reviewType = this.cache.get('reviewType')
  },

  methods: {
    refreshBtnGroup() {
      // 获取要显示的按钮
      this.getButtonsData(this.proInstId)
      // 意见
      this.getCaacOpinion(this.proInstId)
      // 详情
      this.getCaacDetail(this.proInstId)
    },

    // tab 点击事件
    onChange(itemTitle) {
      // 公文详情
      if (itemTitle == 'gwxq') {
        if (this.gwxqFlag) {
          this.getCaacDetail(this.proInstId)
        }
      } else if (itemTitle == 'bsgz') {
        // 版式稿纸
        if (this.bsgzFlag) {
        }
      } else if (itemTitle == 'lzgc') {
        // 流转过程
        if (this.lzgcFlag) {
          this.getCaacDocProcess(this.proInstId)
          this.getListChildSubOperationLogs(this.proInstId)
        }
      }
    },

    // 获取意见
    getCaacOpinion(proInstId) {
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/approval/approvalwrite`),
        method: 'get',
        params: this.$http.adornParams({
          'proInstId': proInstId,
          'systemKey': this.userInfo.systemKey,
          'systemFlag': this.userInfo.systemFlag
        })
      }).then(({data}) => {
        if (data.code == 200) {
          if (data.data != null) {
            this.opinion = data.data
          }
        }
        console.log("------意见-approvalwrite: " + JSON.stringify(data));
      })
    },

    // 获取详情
    getCaacDetail(proInstId) {
      const _this = this
      _this.$httploading({
        url: _this.$http.adornUrl('/caac/oa/affair/admin/schedule/proInstId/' + proInstId),
        method: 'get',
        params: _this.$http.adornParams({
          'systemKey': _this.userInfo.systemKey,
          'systemFlag': _this.userInfo.systemFlag
        })
      }).then(({data}) => {
        console.log("------公文详情-sw: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.detailBody = data.data
          _this.getRelateId(data.data.id);
          _this.openwfneededdata(data.data.extendIdForRelate, proInstId)
          _this.getCaacDocProcess(proInstId)
          _this.getListChildSubOperationLogs(proInstId)
        }
      });
    },

    // 获取详情
    getRelateId(id) {
      const _this = this
      _this.$httploading({
        url: _this.$http.adornUrl('/caac/oa/affair/admin/schedule/proof/' + id),
        method: 'get',
        params: _this.$http.adornParams({
          'systemKey': _this.userInfo.systemKey,
          'systemFlag': _this.userInfo.systemFlag
        })
      }).then(({data}) => {
        console.log("------公文详情-proofBody: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.proofBody = data.data
          _this.getFwDetail(data.data.extendIdForRelate);
          _this.getCaacAttachment(data.data.relateId) // 获取附件
        }
      });
    },

    // 获取正文数据
    getFwDetail(fwEndId) {
      const _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/doc/fw/` + fwEndId),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,
          'systemFlag': this.userInfo.systemFlag,
        })
      }).then(({data}) => {
        if (data.code == 200) {
          _this.fwInfo = data.data;
          _this.getCaacBody(data.data.extendIdForRelate)       // 获取正文
        }
      })
    },

    // 获取正文数据
    getCaacBody(relateId) {
      const _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/maintext/proInstId/` + relateId),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,
          'systemFlag': this.userInfo.systemFlag,
        })
      }).then(({data}) => {
        if (data.code == 200) {
          console.log("------正文-detailDoc: " + JSON.stringify(data.data));
          _this.detailDoc = data.data.doc
          _this.detailOfd = data.data.ofd
        }
      })
    },

    // 获取附件数据
    getCaacAttachment(relateId) {
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/attachmentupload/attachmentinfoOrderByNew`),
        method: 'get',
        params: this.$http.adornParams({
          'bizId': relateId,
          'attachTypeId': 'pageBody_uploadFile',
          'systemKey': this.userInfo.systemKey,
          'systemFlag': this.userInfo.systemFlag,
        })
      }).then(({data}) => {
        if (data.code == 200) {
          _this.detailAttachment = data.data
        }
        console.log("------附件-attachmentinfoOrderBy: " + JSON.stringify(_this.detailAttachment));
      })
    },

    // 获取流转过程
    getCaacDocProcess(proInstId) {
      const _this = this
      this.$httploading({
        url: this.$http.adornUrl(`/caac/oa/component/workflow/workflowController/listProInstIdOperationLogs`),
        method: 'post',
        params: this.$http.adornParams({
          'proInstId': proInstId,
          'systemKey': this.userInfo.systemKey,
          'systemFlag': this.userInfo.systemFlag
        })
      }).then(({data}) => {
        if (data.code == 200) {
          _this.dataList.docProcess = data.data
          this.lzgcFlag = false
        }
        console.log("流转过程: " + JSON.stringify(_this.dataList));
      })
    },

    // 获取子流转过程
    getListChildSubOperationLogs(proInstId) {
      const _this = this
      this.$httploading({
        url: this.$http.adornUrl(`/caac/oa/component/workflow/workflowController/listChildSubOperationLogs`),
        method: 'post',
        params: this.$http.adornParams({
          'proInstId': proInstId,
          'systemKey': this.userInfo.systemKey,
          'systemFlag': this.userInfo.systemFlag
        })
      }).then(({data}) => {
        console.log("子流转过程data: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.dataList.signProcess = data.data
        }
      })
    },

    // 打开发文页面
    openFw() {
//      uni.navigateTo({
//        url:"/pages/caac/send/index?proInstId="+ this.fwInfo.proInstId
//      })
      this.showCompo = true;
      // 调用子组件的方法
//      this.$refs.fwRef.init2(this.fwInfo.proInstId)
    },

    toClose() {
      this.showCompo = false;
    },

    // 获取签批功能
    openwfneededdata(id, proInstId) {
      const _this = this
      let actUrl = '/caac/oa/comm/comm/openwfneededdata'
      _this.$http({
        url: _this.$http.adornUrl(actUrl),
        method: 'get',
        params: _this.$http.adornParams({
          'id': id,             // 详情返回的swId
          'proInstId': proInstId, // proInstId
          'systemKey': _this.userInfo.systemKey,
          'systemFlag': _this.userInfo.systemFlag
        })
      }).then(({data}) => {
        if (data.code == 200) {
          _this.paramObject = data.data
          console.log('paramObject--->' + JSON.stringify(_this.paramObject))
          _this.configCode = data.data.configCode
          // _this.getCaacDetail(proInstId, data.data.configCode)
          _this.getRoleTypesAndActInst(data.data.configId, proInstId)
        }
      })
    },

    //获取签批功能菜单optionBtn02
    getRoleTypesAndActInst(configId, proInstId) {
      const _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/getRoleTypesAndActInst`),
        method: 'post',
        params: this.$http.adornParams({
          'proInstId': proInstId,//发文详情返回的proInstId
          'configId': configId,//openwfneededdata()返回的configId
          'systemKey': this.userInfo.systemKey,
          'systemFlag': this.userInfo.systemFlag
        })
      }).then(({data}) => {
        if (data.code == 200) {
          _this.optionBtn = data.data
          console.log("签批功能菜单optionBtn02: " + JSON.stringify(data.data));
          _this.initActivity()

        }

      })
    },

    // 获取要显示的按钮
    async getButtonsData(proInstId) {
      let _this = this
      await _this.$http({
        url: _this.$http.adornUrl(`/caac/oa/app/getButtonsData`),
        method: 'get',
        params: _this.$http.adornParams({
          'systemKey': _this.userInfo.systemKey,
          'systemFlag': _this.userInfo.systemFlag,
          'proInstId': proInstId,
          'gwType': 'pbjd'
        })
      }).then(({data}) => {
        if (data.code == 200) {
          this.buttonArr = data.data.buttons
          console.log('button--->' + data.data.buttons);
        }
      })
    },

    //获取签批功能菜单
    async initActivity() {
      const _this = this
      let option01 = _this.paramObject
      let option02 = _this.optionBtn.actInstList[0]
      // console.log("option02===: " + JSON.stringify(option02));
      await _this.$http({
        url: _this.$http.adornUrl(`/caac/wfm/ApplicationController/initActivity`),
        method: 'post',
        params: _this.$http.adornParams({
          'systemKey': _this.userInfo.systemKey,
          'systemFlag': _this.userInfo.systemFlag,
          'data': _this.$http.adornData({
            'configId': option01.configId,//openwfneededdata()返回的configId
            'configCode': option01.configCode,
            'proDirId': option01.proDirId,
            'actDefId': option01.actDefId,
            'wfmRoleTypes': option02.wfmRoleTypes,
            'proInstId': option01.proInstId,
            'actInstId': option01.actInstId,
            'workitemId': option01.workitemId,
            'wfmInitPageType': 'running',
            'bizId': option01.bizId
          }),
        })
      }).then(({data}) => {
        console.log("data---->>: " + JSON.stringify(data));
        if (data.code == 200) {
          let operations = data.data.qualifiedOperations
          _this.barList = [] // 重置为空
          if (operations != null && operations.length > 0) {
            //TODO 还需判断其他类型的按钮
            for (let i = 0; i < operations.length; i++) {

              // 同意并退拟稿人
              if (operations[i].operation == 'agreeAndBack') {
                this.barList.push({
                  name: operations[i].operationName,
                  operation: operations[i].operation,
                  icon: 'static/imgs/icon/icon-agree.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-agree-active.png',
                    inactive: 'static/imgs/icon/icon-agree.png'
                  },
                  value: operations[i].operationName,
                  sort: 1
                })
              }

              // 不同意并退拟稿人
              if (operations[i].operation == 'disAgreeAndBack') {
                this.barList.push({
                  name: operations[i].operationName,
                  operation: operations[i].operation,
                  icon: 'static/imgs/icon/icon-tuigwms.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-tuigwms-active.png',
                    inactive: 'static/imgs/icon/icon-tuigwms.png'
                  },
                  value: operations[i].operationName,
                  sort: 2
                })
              }

              // 流转
              if (operations[i].operation == 'complete' || operations[i].operation == 'generalMove') {
                _this.barList.push({
                  name: operations[i].operationName,
                  operation: operations[i].operation,
                  icon: 'static/imgs/icon/icon-transfer.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-transfer-active.png',
                    inactive: 'static/imgs/icon/icon-transfer.png'
                  },
                  value: operations[i].operationName,
                  sort: 3
                })
              }

              // 作废
              if (operations[i].operation == 'reProof' || operations[i].operation == 'cancel') {
                _this.barList.push({
                  name: operations[i].operationName,
                  operation: operations[i].operation,
                  icon: 'static/imgs/icon/icon-delete.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-delete-active.png',
                    inactive: 'static/imgs/icon/icon-delete.png'
                  },
                  value: operations[i].operationName,
                  sort: 4
                })
              }

              // 送文印室排版
              if (operations[i].operation == 'spb') {
                _this.barList.push({
                  name: operations[i].operationName,
                  operation: 'spb',
                  icon: 'static/imgs/icon/icon-delete.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-handover-active.png',
                    inactive: 'static/imgs/icon/icon-handover.png'
                  },
                  value: operations[i].operationName,
                  sort: 5
                })
              }
            }

            console.log('barButton--->' + JSON.stringify(this.buttonArr));
            // 功能按钮筛选
            if (this.util.isNotEmpty(this.buttonArr)) {
              let newBarList = []
              this.buttonArr.filter((b, index) => this.buttonArr.indexOf(b) === index).forEach((item) => {
                let arr = this.barList.filter(t => t.operation == item)
                if (arr != null && arr.length > 0) {
                  newBarList.push(arr[0])
                }
              })
              this.barList = newBarList
            } else {
              this.barList = []//如果获取到的按钮为空，则置空
            }

            console.log('barList--->' + JSON.stringify(_this.barList));
            // 大于三个添加更多按钮,第四个按钮为更多操作
            if (_this.barList.length > 3) {
              _this.barList.sort((a, b) => a.sort - b.sort);
              let more = {
                name: '更多',
                operation: 'more',
                icon: 'static/imgs/icon/icon-more.png',
                iconTab: {
                  active: 'static/imgs/icon/icon-more-active.png',
                  inactive: 'static/imgs/icon/icon-more.png',
                },
                value: '更多操作',
              };
              _this.barList.splice(3, 0, more);
            }
          }

        } else {
          console.log("出错了: " + JSON.stringify(data));
        }

      })
    },

    // 点击tabbar
    onClick(item) {
      this.btnFunction(item)
    },

    // 下边菜单点击功能
    btnFunction(item) {

      // 更多操作
      if (item == 'more') {
        this.showShare = true
      }
      // 流转
      if (item == 'complete' || item == 'generalMove') {
        this.showTrans = true
        //调用子组件的方法
        this.$refs.trans.getSelectPerson(this.proInstId, this.detailBody.drafterId)
      }
      // 作废
      if (item == 'reProof') {
        this.reProofDialog('reProof');
      }
      // 作废
      if (item == 'cancel') {
        this.reProofDialog('cancel');
      }
      // 送文印室排版
      if (item == 'spb') {
        this.spbDialog();
      }
      // 同意并退拟稿人
      if (item == 'agreeAndBack') {
        this.agreeDialog();
      }
      // 不同意并退拟稿人
      if (item == 'disAgreeAndBack') {
        this.disAgreeDialog();
      }
    },

    // 关闭更多操作
    closeShare(item) {
      this.showShare = false
      this.btnFunction(item)
    },

    // 关闭流转
    closeTrans() {
      this.showTrans = false
    },

    // 同意并退拟稿人提示框
    agreeDialog() {
      this.$dialog.confirm({
        confirmButtonColor: '#1989fa',
        title: '系统提示',
        message: '您确定要操作吗?',
      }).then(() => {
        this.agreeAndBack('同意')
      }).catch(() => {
        // on cancel
      });
    },

    // 不同意并退拟稿人提示框
    disAgreeDialog() {
      this.$dialog.confirm({
        confirmButtonColor: '#1989fa',
        title: '系统提示',
        message: '您确定要操作吗?',
      }).then(() => {
        this.agreeAndBack('不同意')
      }).catch(() => {
        // on cancel
      });
    },

    agreeAndBack(opinionMsg) {
      const _this = this
      let opinionType;
      if (_this.paramObject.actDefId === 'bmld_pbjd') {
        opinionType = "bmldProofReview";
      } else if (_this.paramObject.actDefId === 'zhs_pbjd') {
        opinionType = "zhsProofReview";
      }

      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/approval/findopinion`),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,
          'systemFlag': this.userInfo.systemFlag,
          'proInstId': _this.paramObject.proInstId,
          'workItemId': _this.paramObject.workitemId,
          'reviewType': opinionType,
        })
      }).then(({data}) => {
        if (data.code == 200) {
          let id = data.data != null ? data.data.id : null;
          this.$httploading({
            url: this.$http.adornUrl(`/caac/oa/component/approval/saveopinion`),
            method: 'post',
            params: {
              'systemKey': this.userInfo.systemKey,
              'systemFlag': this.userInfo.systemFlag,
            },
            data: this.$http.adornData({
              'proInstId': _this.paramObject.proInstId,//发文详情返回的proInstId
              'workItemId': _this.paramObject.workitemId,//
              'actInstId': _this.paramObject.actInstId,//
              'opiniontype': opinionType,
              'opinion': opinionMsg,
              'isApproval': '1',
              'id': id,
            })
          }).then(({data}) => {
            console.log("-------saveopinion: " + JSON.stringify(data));
            if (data.code == 200) {
              this.$http({
                url: this.$http.adornUrl(`/caac/wfm/ApplicationController/listNextActivities?systemKey=` + this.userInfo.systemKey + `&systemFlag=` + this.userInfo.systemFlag),
                method: 'post',
                params: {
                  'data': this.$http.adornData({
                    wfmData: {
                      'configId': this.paramObject.configId,
                      'configCode': this.paramObject.configCode,
                      'proDirId': this.paramObject.proDirId,// 详情返回的proInstId
                      'actDefId': this.paramObject.actDefId,//
                      'wfmRoleTypes': this.optionBtn.actInstList[0].wfmRoleTypes,
                      'proInstId': this.paramObject.proInstId,
                      'actInstId': this.paramObject.actInstId,//
                      'workitemId': this.paramObject.workitemId,
                    }
                  })
                }
              }).then(({data}) => {
                if (data.code == 200) {
                  let nextActivities = data.data.nextActDefIds.filter(n => n.actDefId == 'SecjdUser');
                  this.$httploading({
                    url: this.$http.adornUrl(`/caac/wfm/ApplicationController/gotoActivity`),
                    method: 'post',
                    params: {
                      systemKey: this.cache.get('userInfo').systemKey,
                      systemFlag: this.cache.get('userInfo').systemFlag,
                      data: this.$http.adornData({
                        wfmData: {
                          'nextActivities': nextActivities,
                          'configId': _this.paramObject.configId,
                          'proDirId': _this.paramObject.proDirId,
                          'actDefId': _this.paramObject.actDefId,
                          'proInstId': _this.paramObject.proInstId,
                          'actInstId': _this.paramObject.actInstId,
                          'workitemId': _this.paramObject.workitemId,
                          'formData': {
                            'fwProofForm': this.detailBody,//详情
                          },
                          "gotoResourceIds": "user:" + this.detailBody.drafterId,
                          'gotoActDefId': 'SecjdUser'
                        },
                      })
                    }
                  }).then(({data}) => {
                    console.log("gotoActivity-->>: " + JSON.stringify(data));
                    if (data.code == 200) {
                      this.$toast('操作成功');
                      uni.redirectTo({
                        url: '/pages/caac/send/signList'
                      })
                    } else {
                      _this.$toast(data.message + ' code:' + data.code)
                    }
                  })
                } else {
                  this.$toast(data.message + ' code:' + data.code)
                }

              })
            } else {
              _this.$toast(data.message + ' code:' + data.code)
            }
          })
        } else {
          this.$toast(data.message)
        }

      })
    },

    // 作废提示框
    reProofDialog(type) {
      this.$dialog.confirm({
        confirmButtonColor: '#1989fa',
        title: '系统提示',
        message: '您确定要操作吗?',
      }).then(() => {
        if (type == 'reProof') {
          this.reProof()
        } else if (type == 'cancel') {
          this.cancelProof();
        }
      }).catch(() => {
        // on cancel
      });
    },

    cancelProof() {
      const _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/doc/fwend/cancelproof`),
        method: 'post',
        params: {
          'systemKey': this.userInfo.systemKey,
          'systemFlag': this.userInfo.systemFlag,
        },
        data: this.$http.adornData({
          'fwEndId': _this.proofBody.fwEndId,
          'id': _this.proofBody.scheduleId,
          'proofRemark': 'cancel',
          'proofResult': '0',
          'relateId': _this.proofBody.relateId,
        })
      }).then(({data}) => {
        if (data.code == 200) {
          _this.$toast('操作成功')
          uni.redirectTo({
            url: '/pages/caac/send/signList'
          })
        } else {
          _this.$toast(data.message + ' code:' + data.code)
        }

      })
    },

    reProof() {
      const _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/doc/fwend/proof`),
        method: 'post',
        params: {
          'systemKey': this.userInfo.systemKey,
          'systemFlag': this.userInfo.systemFlag,
        },
        data: this.$http.adornData({
          'fwEndId': _this.proofBody.fwEndId,
          'id': _this.proofBody.scheduleId,
          'proofRemark': 'cancel',
          'proofResult': '0',
          'relateId': _this.proofBody.relateId,
        })
      }).then(({data}) => {
        if (data.code == 200) {
          this.completeWorkitem();
        } else {
          _this.$toast(data.message + ' code:' + data.code)
        }

      })
    },

    completeWorkitem() {
      const _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/listNextActivities?systemKey=` + this.userInfo.systemKey + `&systemFlag=` + this.userInfo.systemFlag),
        method: 'post',
        params: {
          'data': this.$http.adornData({
            wfmData: {
              'configId': this.paramObject.configId,
              'configCode': this.paramObject.configCode,
              'proDirId': this.paramObject.proDirId,// 详情返回的proInstId
              'actDefId': this.paramObject.actDefId,//
              'wfmRoleTypes': this.optionBtn.actInstList[0].wfmRoleTypes,
              'proInstId': this.paramObject.proInstId,
              'actInstId': this.paramObject.actInstId,//
              'workitemId': this.paramObject.workitemId,
            }
          })
        }
      }).then(({data}) => {
        if (data.code == 200) {
          let nextActivities = data.data.nextActDefIds.filter(n => n.actType == 'end');
          this.$httploading({
            url: this.$http.adornUrl(`/caac/wfm/ApplicationController/completeWorkitem`),
            method: 'post',
            params: {
              'systemKey': _this.userInfo.systemKey,
              'systemFlag': _this.userInfo.systemFlag,
              data: this.$http.adornData({
                fwProofForm: _this.detailBody,//详情
                wfmData: {
                  'configId': _this.paramObject.configId,
                  'proDirId': _this.paramObject.proDirId,//发文详情返回的proInstId
                  'actDefId': _this.paramObject.actDefId,//
                  'proInstId': _this.paramObject.proInstId,
                  'actInstId': _this.paramObject.actInstId,//
                  'workitemId': _this.paramObject.workitemId,
                  'nextActivities': nextActivities
                },
              })
            }
          }).then(({data}) => {
            console.log("------结束公文-completeWorkitem-->>: " + JSON.stringify(data));
            if (data.code == 200) {
              _this.$toast('操作成功')
              uni.redirectTo({
                url: '/pages/caac/send/signList'
              })
            } else {
              _this.$toast(data.message + ' code:' + data.code)
            }
          })
        } else {
          this.$toast(data.message + ' code:' + data.code)
        }

      })
    },

    // 送文印排版
    spbDialog() {
      this.$dialog.confirm({
        confirmButtonColor: '#1989fa',
        title: '系统提示',
        message: '您确定要操作吗?',
      }).then(() => {
        this.spb();
      }).catch(() => {
        // on cancel
      });
    },
    spb() {
      const _this = this
      let url = '/caac/oa/doc/fwend/' + _this.proofBody.extendIdForRelate + '/' + _this.proofBody.scheduleId
      this.$httploading({
        url: this.$http.adornUrl(url),
        method: 'post',
        params: {
          'systemKey': _this.userInfo.systemKey,
          'systemFlag': _this.userInfo.systemFlag,
        }
      }).then(({data}) => {
        if (data.code == 200) {
          _this.$toast('操作成功')
          _this.completeWorkitem();
        } else {
          _this.$toast(data.message + ' code:' + data.code)
        }
      })
    },

    // 打开详情
    openDetail() {
      this.showDetail = true;
      // 调用子组件的方法
      this.$refs.detail.init(this.paramObject.bizId)
    },
    // 关闭详情
    closeDetail() {
      this.showDetail = false
    },
  },
}

</script>

<style scoped>
/* 意见相关样式 */
.opinion{
  display: flex;
  flex-direction: column;
  margin: 0 32rpx;
  padding: 20rpx 0rpx;
  overflow: hidden;
  font-size: 28rpx;
  line-height: 24px;
  border-bottom: 1px solid #ebedf0;

}
.opinion .opinion-title{
  text-align: left;
  padding-bottom: 14rpx;
}
.opinion .opinion-box{
  margin-bottom: 20rpx;
}
.opinion .opinion-left{
  text-align: left;
  color: #323233;
}
.opinion .opinion-right{
  text-align: right;
  color: #969799;
}
.opinion .opinion-right .opinion-user{
  font-weight: 400;
  color: #000000;
}
.opinion .opinion-right .opinion-date{
  color: #323233;
  margin-left: 20rpx;
}
.van-cell__title {
  min-width: 50%;

span {
  display: inline-block;
  text-align: left;
  word-break: break-all;
}
}

/deep/ .van-collapse-item__content {
  padding: 0px;
  color: #969799;
  font-size: 14px;
  line-height: 1.5;
  background-color: #fff
}

/deep/ .content-border {
  border-bottom: 1rpx solid #e4e4e4;
  display: flex;
}
.content-title {
  background-color: #f2f2f2;
  padding: 10px 15px;
  color: #646566;
}
.content-value {
  padding: 10px 15px;
  text-align: right;
}
.content-red {
  color: #ed1c24;
}
.content-blue {
  color: #0081ff;
}
</style>
